package MapDemo.demo2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class test2 {
    public static void main(String[] args){
        // 创建一个Map集合
        HashMap<String,ArrayList<String>> hm = new HashMap<>();

        // 添加数据
        ArrayList<String> a1 = new ArrayList<>();
        Collections.addAll(a1,"南京市","扬州市","苏州市","无锡市","常州市");
        ArrayList<String> a2 = new ArrayList<>();
        Collections.addAll(a2,"武汉市","孝感市","十堰市","宜昌市","鄂州市");
        ArrayList<String> a3 = new ArrayList<>();
        Collections.addAll(a3,"石家庄市","唐山市","邢台市","保定市","张家口市");

        // 给Map集合添加元素
        hm.put("江苏省", a1);
        hm.put("湖北省", a2);
        hm.put("河北省", a3);

        // 遍历Map集合
        hm.forEach((String key, ArrayList<String> value) -> {
            StringBuilder sb = new StringBuilder();
            // 遍历内部集合,添加元素
            value.forEach(s -> sb.append(s).append(","));
            sb.deleteCharAt(sb.length() - 1);
            System.out.println(key + "=" + sb);
        });

    }
}
